﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EDiamondModel;
using System.Data;

public partial class UControl_UCSanPhamTheoNhom : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Session["GioHang"] = null;
        if (!IsPostBack)
        {
            EDiamondEntities1 db = new EDiamondEntities1();
            string idLSP = Request.QueryString["idLSP"];
            string IDLoai = Request.QueryString["IDLoai"];

            if (!string.IsNullOrEmpty(idLSP))
            {
                int id = Convert.ToInt32(idLSP);
                var sp = db.SanPhams.SingleOrDefault(p => p.SanPhamID == id);
                var nhom = db.LoaiSanPhams.Single(p => p.MaLoai == sp.MaLoai);
                lblTieuDe.Text = nhom.TenLoai;
            }
            else if (!string.IsNullOrEmpty(IDLoai))
            //else
            {
                //if (idloai == "1")
                //    lblTieuDe.Text = "Sản phẩm của chúng tôi";


                lvwSanPham.DataSourceID = "TatcaLoai";
                lvwSanPham.DataBind();
            }


        }
    }
    protected void DatHang_Click(object sender, EventArgs e)
    {
        List<MuaSanPham> tb;
        if (Session["GioHang"] == null)
        {
            tb = new List<MuaSanPham>();
            Session["GioHang"] = tb;
        }
        else
            tb = Session["GioHang"] as List<MuaSanPham>;
        LinkButton li = sender as LinkButton;
        int SanPhamID = li.TabIndex;

        GioHang.ThemSp(SanPhamID,1);
        double sl = GioHang.TongSanpham();
        double tg = GioHang.TongTrigia();
        Label SLuong = this.Parent.Page.Master.FindControl("SLuong") as Label;
        SLuong.Text = "<b>" + sl.ToString() + "<b>";
        Label TGia = this.Parent.Page.Master.FindControl("TGia") as Label;
        TGia.Text = "<b>" + tg.ToString() + "<b>";
    }
}